package com.wanyang.service;

import com.wanyang.bo.MemberBO;
import com.wanyang.dos.SearchHistoryDO;
import com.wanyang.dto.SearchDTO;
import com.wanyang.mapper.SearchHistoryDOMapper;
import com.wanyang.utils.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SearchServiceImpl implements SearchService {
    @Resource
    private SearchHistoryDOMapper searchHistoryDOMapper;

    @Override
    public void writeSearchHistory(SearchDTO searchDTO) {
        MemberBO memberBO = UserContext.get();

        if (memberBO != null) {
            SearchHistoryDO searchHistoryDO = new SearchHistoryDO();
            searchHistoryDO.setSearchContent(searchDTO.getSearchContent());
            searchHistoryDO.setCreateTime(DateUtil.currentUnixTime());
            searchHistoryDO.setType(searchDTO.getType().toString());
            searchHistoryDO.setMemberId(memberBO.getId());
            searchHistoryDO.setIsDelete(false);
            searchHistoryDOMapper.insertSelective(searchHistoryDO);
        }


    }
}
